/**
 iTextUploader
 (C) 2008 Asgl (myselftdev@gmail.com)
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; version 2
 of the License.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

/* Revision: $Id: BrowseView.m 20 2008-08-21 15:44:04Z myselftdev $ */

#import "BrowseView.h"

@implementation BrowseView

- (id)initWithFrame:(CGRect)frame mainView:(MainView*)view
{
	if (self = [super initWithFrame:frame])
	{
		mainView = [view retain];
		
		CGRect contentRect = CGRectMake(0.0, 0.0, 320.0, (460.0 - 49.0));
		
		theWebView = [ [UIWebView alloc] initWithFrame:contentRect];
		theWebView.delegate = self;
		[self addSubview:theWebView];
		
		self.backgroundColor = [UIColor colorWithWhite:1.0 alpha:1.0];
		
		[self loadHome];
	}
	return self;
}

-(void) loadHome
{		
	[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
	
	NSString *URLString = [NSString stringWithFormat:@"%@%@", @BASEURL, @"app/"];
	NSURLRequest *aRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:URLString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
	[theWebView loadRequest:aRequest];
}

- (void)webViewDidFinishLoad:(UIWebView *)aWebView
{
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

- (void)webView:(UIWebView *)aWebView didFailLoadWithError:(NSError *)error
{
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
	
	NSURL *errorURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ConnectionError" ofType:@"html"]];
	NSURLRequest *aRequest=[NSURLRequest requestWithURL:errorURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
	[theWebView loadRequest:aRequest];
}

-(void)dealloc
{
	[theWebView release];
	[mainView release];
	
	[super dealloc];
}
@end
